package com.object.module.lq.chatroom.websocketcomfig;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;

import java.util.Map;

import static com.object.module.lq.chatroom.websocketcomfig.ChatHandler.getUrlParams;


public class TeacherWebSocketHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof WebSocketServerProtocolHandler.HandshakeComplete) {
            WebSocketServerProtocolHandler.HandshakeComplete handshakeComplete = (WebSocketServerProtocolHandler.HandshakeComplete) evt;
            String uri = handshakeComplete.requestUri();
            HttpHeaders entries = handshakeComplete.requestHeaders();
            System.out.println("userEventTriggered:entries" + entries + "\nurl:" + uri);
            Map paramMap = getUrlParams(uri);
            Long id = Long.valueOf(String.valueOf(paramMap.get("id")));
            ChatHandler.getMap().put(id, ctx.channel());
            /**
             * 实现自己的初始化操作
             */
        }
        super.userEventTriggered(ctx, evt);
    }
}